
package com.cosc645.ecash;

import java.math.BigInteger;
import java.util.Scanner;

public class TestDriver {

    public static final int MONEY_ORDER_SIZE = 100;
    public static void main(String[] args)  {

        Alice alice = new Alice();
        Bob bob = new Bob();
        Bank bank = new Bank();
        Scanner scan = new Scanner(System.in);

        System.out.println("Enter amount of the money order:");
        double amount = 12;//scan.nextDouble();

        alice.createMoneyOrder(amount);
        //alice.identityEncoding();
        alice.makeEnvelope(bank.getPublicKey());

               
        alice.commitMoneyOrder();
        BigInteger moneyOrderBytes = bank.checksMoneyOrders(alice, amount);
        BigInteger t = bank.signMoneyOrder(moneyOrderBytes, amount);
        System.out.println("T: " + t);
        
        
        //alice opens the envelope and gives to bob
        BigInteger unblindedT = alice.unblind(bank.getPublicKey(), t);
        System.out.println("unblindedT decrypted: "+ unblindedT);
           
        //proof that we can get original M back out of above
        //BigInteger originalM = unblindedT.modPow(bank.getPublicKey().getPublicExponent(), bank.getPublicKey().getModulus());
        //System.out.println("OriginalM decrypted: "+ originalM);
        
        
       // BigInteger aliceOpensEnv = alice.anotherUnblind(bank.getPublicKey(), t);
        BigInteger bobsM = bob.verifyBankSignature(bank.getPublicKey(), unblindedT);
        
        bank.cashMoneyOrder(t, unblindedT, bobsM, bob);
        System.out.println("Alice's balance is $"+bank.getAmount(alice.getClass()));

        System.out.println("Bob is now trying to cash the same money order again");
        bank.cashMoneyOrder(t, unblindedT, bobsM, bob);

        System.out.println("Now passing a fake money order to the bank...");
        //bob just tries to forge the t since alice wouldn't unblind a forged bank signature
        bank.cashMoneyOrder(t.add(t),unblindedT, bobsM, bob);
               
        
    }

}
